<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增检测报告基本')" />
	<link th:href="@{/css/boot.css}" rel="stylesheet" />
	<link th:href="@{/css/city-picker.css}" rel="stylesheet"  />
	<script th:src="@{/js/jquery.m.js}"></script>
	<script th:src="@{/js/boot.js}"></script>
	<script th:src="@{/js/city-picker.data.js}"></script>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-js" />
	<th:block th:include="include :: bootstrap-fileinput-css" />
	<th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tJcJcbg-add">
			<div class="form-group">
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">报告名称：</label>
				<div class="col-sm-6">
					<input id="reportName" name="reportName"  placeholder="请输入报告名称" class="form-control" type="text">
				</div>
				</div>
				<div class="col-sm-6">
					<label class="col-sm-4 control-label">报告编号：</label>
					<div class="col-sm-6">
						<input id="reportId" name="reportId" class="form-control" placeholder="请输入报告编号" type="text">
					</div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">受检单位：</label>
				<div class="col-sm-6">
					<div class="input-group" style="width: 100%">
						<!--<select name="checkName" class="form-control m-b" id = "check"  onclick="selectRadioUser" onchange="check7()"  >-->
							<!--<option value="" >请选择受检单位</option>-->
						<!--</select>-->
                        <input id="checkName" placeholder="请输入受检单位" name="checkName" class="form-control"  onclick="selectRadioUser()"  type="text" >
						<input type="hidden" value="" id="flzddwId" name="flzddwId">
					</div>
				</div>
				</div>
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">项目名称：</label>
				<div class="col-sm-6">
					<input id="itemName" name="itemName" placeholder="请输入项目名称" onclick="itemName1()" class="form-control" type="text">
				</div>
				</div>
			</div>
			<div class="form-group" style="margin-bottom: 0px">

					<div class="col-sm-6">
					<label class="col-sm-4 control-label">项目地址：</label>
					<div class="col-sm-6">
						<input  id="address" name="itemAddress" class="form-control" placeholder="请输入项目地址" type="text">
					</div>
                    </div>

				<div class="col-sm-6">
				<label class="col-sm-4 control-label">防雷类别：</label>
				<div class="col-sm-6">
                    <select name="thunderCategory" id = "check2" class="form-control m-b" th:with="type=${@dict.getType('t_jc_flzddw_type')}">
                        <option value=0>请选择防雷类别</option>
						<option th:each="dict :${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
				</div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">行业属性：</label>
				<div class="col-sm-6">
					<div class="input-group" style="width: 100%">
                        <select name="tradeProperty" class="form-control m-b" id = "check8" th:with="type=${@dict.getType('t_jc_flzddw')}">
                            <option  value= 0>请选择行业属性</option>
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
					</div>
				</div>
				</div>
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">检测周期：</label>
				<div class="col-sm-6">
					<div class="input-group" style="width: 100%">
                        <select name="searchCycle" class="form-control m-b" id = "check3" onchange="check11()" th:with="type=${@dict.getType('t_jc_flzddw_time')}">
                            <option value=0>请输入检测周期</option>
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
					</div>
				</div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">联系人：</label>
				<div class="col-sm-6">
                    <input  name="contacts"  placeholder="请输入联系人名称" class="form-control" type="text" id="check9">
				</div>
				</div>
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">检测年度：</label>
				<div class="col-sm-6">
					<!--<input id="detectionYear" name="detectionYear" class="form-control" type="text">-->
					<input name="detectionYear" type="text" class="form-control" id="laydate-demo-3" placeholder="请选择检测年度" >
				</div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">检测日期：</label>
				<div class="col-sm-6">
					<input name="detectionDate" type="text" class="form-control" id="laydate-demo-1" placeholder="请选择检测日期" onclick="day1()">
				</div>
				</div>
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">检测有效期：</label>
				<div class="col-sm-6">
					<input name="detectionDateEnd" type="text" class="form-control" id="laydate-demo-2"  placeholder="请选择检测有效期">
				</div>
				</div>
			</div>
			<div class="form-group" style="margin-bottom: 0px">
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">检测结论：</label>
				<div class="col-sm-6">
					<input id="detectionVerdict" placeholder="请输入检测结论" name="detectionVerdict" class="form-control" type="text">
				</div>
				</div>
				<!--<div class="col-sm-6">-->
				<!--<label class="col-sm-4 control-label">检测机构id：</label>-->
				<!--<div class="col-sm-6">-->
                    <!--<select name="detectionId" class="form-control m-b" id = "checkTo"  onchange="check6()" >-->
                        <!--<option value="" >请选择检测机构id</option>-->
                    <!--</select>-->
				<!--</div>-->
				<!--</div>-->
				<div class="col-sm-6">
					<div class="form-group">
					<label class="col-sm-4 control-label">检测机构名称：</label>
					<div class="col-sm-6">
						<!--<input id="detectionName1" name="detectionName" placeholder="请输入检测机构名称" class="form-control" type="text" >-->
						<select name="detectionId" id = "detectionName1" class="form-control m-b" onclick="query()">
							<option value= 0>请输入检测机构名称</option>
						</select>
						<input type="hidden" name="detectionName" id="checkTo">
					</div>
					</div>
				</div>

			</div>
			<div class="form-group">
				<div class="col-sm-6">
				<label class="col-sm-4 control-label">联系电话：</label>
				<div class="col-sm-6">
					<input id="check5" name="contactsPhone"  placeholder="请输入联系人电话" class="form-control" type="text" >
                    <!--<button type="button" class="btn btn-success" onclick="selectRadioUser()">请选择防雷单位社会统一代码</button>-->
				</div>
				</div>
				<div class="col-sm-6">
					<label class="col-sm-4 control-label">备注：</label>
					<div class="col-sm-6">
						<input id="remark" name="remark" class="form-control" placeholder="请输入备注" type="text">
					</div>
				</div>
			</div>
		</form>
	</div>
	<div class="form-group">
		<div class="col-sm-6">
			<input type="file" id="file" name="file1"/>
			<input type="button" id = "upLoad" class="btn btn-primary btn-sm" value="上传"   />
	</div>
	<!--<div class="form-group">
		<label class="font-noraml">多文件上传</label>
		<div class="file-loading">
			<input id="fileinput-demo-1" type="file" multiple>
		</div>
	</div>-->
	<div class="row">
		<div class="col-sm-offset-5 col-sm-10">
			<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保存</button>&nbsp;
			<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
		</div>
	</div>
	<script th:src="@{/js/ajaxfileupload.js}" ></script>
    <script type="text/javascript">
		function checkNameVal(id,val) {
			$('#checkName').val(val);
			$('#flzddwId').val(id);
			checkName();
		}
		var prefix = ctx + "system/tJcJcbg";
        var prefix1 = ctx + "system/tJcFlzddw";
        var prefix2 = ctx + "system/tJcJcbgYw";
		$("#laydate-demo-1").datetimepicker({
			format: "yyyy-mm-dd",
			minView: "month",
			autoclose: true
		});
		$("#laydate-demo-2").datetimepicker({
			format: "yyyy-mm-dd",
			minView: "month",
			autoclose: true
		});
	/*	$("#laydate-demo-3").datetimepicker({
			format: "yyyy",
			minView: "year",
			autoclose: true
		});*/
		layui.use('laydate', function() {
			var laydate = layui.laydate;
			laydate.render({
				elem: '#laydate-demo-3'
				,type: 'year'
			});
		});

		$("#form-tJcJcbg-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});

		$(function () {
			check();
            // checkTo();
			detectionName1();
		})
		$(function(){
			var data = new Date();
			var data1 = data.toLocaleDateString();
			var data2 = data.getFullYear();
			$('#laydate-demo-1').val(data1);
			$('#laydate-demo-3').val(data2);
            $('#laydate-demo-2').val(data1);
		})
		function check() {
			$.ajax({
				url: ctx + "system/tJcFlzddw/list",
				type: "post",
				dataType:"json",
				success:function (data) {
                    var data2 = data.rows;
                    // alert(data2[i].unitName);
                    // console.log(data2.length);
                    for (var i in data2) {
                            if (data2[i].unitName != null) {
                                $("#check").append("<option value='" + data2[i].unitName + "'>" + data2[i].unitName + "</option>");
                            }

                    }
                }
			})
		}
		function query(){
			var detectionName = $("#detectionName1 option:selected").text();
			$("#checkTo").val(detectionName)
		}
		function detectionName1(){
            $.ajax({
                url: ctx + "system/tJcFlzddw/option",
                type: "post",
                dataType:"json",
                success:function (data) {
                    var data2 = data.rows;
                    // alert(data2[i].unitName);
                    // console.log(data2.length);
                    // debugger
                    for (var i in data2) {

                        if (data2[i].agencyName != null) {
                            $("#detectionName1").append("<option value='" + data2[i].code + "'>" + data2[i].agencyName + "</option>");
                        }

                    }
                }
            })
        }
        // function detectionName1(){
        //     var code = $('#checkTo option:selected').text();
		//     $.ajax({
        //         url: ctx + "system/tJcJcbg/codeTo",
        //         data:{"code":code},
        //         type: "post",
        //         dataType:"json",
        //         success : function (data) {
        //             // debugger
        //             $("#detectionName1").val(data[0].agencyName);
		//
		//
        //         }
        //     })
        // }
		function checkName(){
			// debugger
			var creditCode = $('#flzddwId').val();
			$.ajax({
				url: ctx + "system/tJcFlzddw/selectTo",
                data:{"creditCode":creditCode},
				type: "get",
				dataType:"json",
				success:function (data) {
					// alert(data2[i].unitName);
					// console.log(data2.length);
							if (data.thunderCategory !=null) {
                                    $("#check2 option[value = 0]").remove();
                                    $("#check2").val(data.thunderCategory)
							}
							if(data.tradeProperty !=null){
                                    $("#check8 option[value = 0]").remove();
                                    $("#check8").val(data.tradeProperty)
                                }

							if(data.searchCycle !=null){
                                    $("#check3 option[value = 0]").remove();
                                    $("#check3").val(data.searchCycle)
                            }
							if(data.contacts !=null){
							    $("#check9").val(data.contacts)
                            }
							if(data.contactsPhone !=null){
							    $("#check5").val(data.contactsPhone)
                            }
							if(data.unitAddress != null){
							    // console.log();
                                // $('[data-toggle="city-picker"]').val(data.administrativeRegion);
                                // $('#city-picker3').citypicker('refresh');
								$("#address").val(data.unitAddress)
                            }

					}

			})
		}
		function itemName1(){
			var reportName = $("#reportName").val();
			$("#itemName").val(reportName);
		}
       /* function cycle(){
			debugger
			var data = $("#check5").val()
			var time = $("#laydate-demo-1").val();
			var time1 = new Date(time);

			var vaild1  = $("#laydate-demo-2").val();
			if(time1 != null ){
				if(data == 1){
					vaild1 = time1.setMonth(time1.getMonth()+6);
					alert(vaild1)
				}else if(data == 2){
					vaild1 = time1.setFullYear(time1.getFullYear()+1);
					alert(vaild1)
				}
				$("#laydate-demo-2").val(vaild1);
			}

		}*/
		function day1() {
			// debugger
			var data = $("#check3").val()
			var time = $("#laydate-demo-1").val();
			var time1 = new Date(time);
			if(time != null ){
				if(data == 1){
					time1.setMonth(time1.getMonth()+6);
					var year = time1.getFullYear();
					var month = time1.getMonth() +1 < 10 ? "0" + (time1.getMonth() + 1) : time1.getMonth() + 1;
					var date = time1.getDate() < 10 ? "0" + time1.getDate() : time1.getDate();
					var t1 = year+'/'+month+'/'+date;
					$("#laydate-demo-2").val(t1);
				}else if(data == 2){
                    time1.setFullYear(time1.getFullYear()+1);
                    var year1 = time1.getFullYear();
                    var month1 = time1.getMonth() +1 < 10 ? "0" + (time1.getMonth() + 1) : time1.getMonth() + 1;
                    var date1 = time1.getDate() < 10 ? "0" + time1.getDate() : time1.getDate();
                    var t2 = year1+'/'+month1+'/'+date1;
					$("#laydate-demo-2").val(t2);
				}else{
                    var year2 = time1.getFullYear();
                    var month2 = time1.getMonth() +1 < 10 ? "0" + (time1.getMonth() + 1) : time1.getMonth() + 1;
                    var date2 = time1.getDate() < 10 ? "0" + time1.getDate() : time1.getDate();
                    var t3 = year2+'/'+month2+'/'+date2;
					$("#laydate-demo-2").val(t3);
				}
			}

		}
		function check11(){
		    debugger
            var data = $("#check3").val()
            var time = $("#laydate-demo-1").val();
            var time1 = new Date(time);
            if(time != null ){
                if(data == 1){
                    time1.setMonth(time1.getMonth()+6);
                    var year = time1.getFullYear();
                    var month = time1.getMonth() +1 < 10 ? "0" + (time1.getMonth() + 1) : time1.getMonth() + 1;
                    var date = time1.getDate() < 10 ? "0" + time1.getDate() : time1.getDate();
                    var t1 = year+'/'+month+'/'+date;
                    $("#laydate-demo-2").val(t1);
                }else if(data == 2){
                    time1.setFullYear(time1.getFullYear()+1);
                    var year1 = time1.getFullYear();
                    var month1 = time1.getMonth() +1 < 10 ? "0" + (time1.getMonth() + 1) : time1.getMonth() + 1;
                    var date1 = time1.getDate() < 10 ? "0" + time1.getDate() : time1.getDate();
                    var t2 = year1+'/'+month1+'/'+date1;
                    $("#laydate-demo-2").val(t2);
                }else{
                    var year2 = time1.getFullYear();
                    var month2 = time1.getMonth() +1 < 10 ? "0" + (time1.getMonth() + 1) : time1.getMonth() + 1;
                    var date2 = time1.getDate() < 10 ? "0" + time1.getDate() : time1.getDate();
                    var t3 = year2+'/'+month2+'/'+date2;
                    $("#laydate-demo-2").val(t3);
                }
            }

        }
        function selectRadioUser(){

			$.modal.open("选择用户", prefix + "/radio");
        }

		// function submitHandler() {
	    //     if ($.validate.form()) {
	    //         $.operate.save(prefix + "/add", $('#form-tJcJcbg-add').serialize());
	    //     }
	    // }
		$(function () {
			$("#upLoad").click(function () {
				ajaxFile();
			})
		})
		function ajaxFile() {
			var file1 = $("#file").text();
			var
			$.ajaxFileUpload
			(
					{
						url: prefix2 +'/fileup', //用于文件上传的服务器端请求地址
						secureuri: false, //是否需要安全协议，一般设置为false
						fileElementId: 'file', //文件上传域的ID
						data:{file1:file1,},
						success: function (data)  //服务器成功响应处理函数
						{


						},
						error: function (data, status, e)//服务器响应失败处理函数
						{
							alert(e);
						}
					}
			)
			return false;
		}
	/*	$(document).ready(function () {
			$("#fileinput-demo-1").fileinput({
				'theme': 'explorer-fas',
				'uploadUrl': ctx + 'common/upload',
				overwriteInitial: false,
				initialPreviewAsData: true,
				showPreview:false,
				// initialPreview: [
				//
				// ]
			});
		});*/
		function submitHandler() {

           /* $.ajax({
                url : ctx + "system/tJcFlzddw/list",
                type:"post",
                dataType :"json",
                success : function (data){
                    var data2 = data.rows;
                    //检测周期
                    var dataTime = data2.searchCycle;
                    //检测日期
                    var data3 = data2.detectionDate;
                    //检测有效期
                    debugger
                    var data4 = data2.detectionDateEnd;
                    var data5 = data3.setMonth(data3.getMonth() +6);

                    var data6 = data3.setFullYear(data3.getFullYear()+1);

                    if(dataTime == 1){
                        data4 = data5;
                    }else if(dataTime ==2){
                        data4 = data6;

                    }
                    $("#laydate-demo-2").val(data4);
                }
            });*/


			if ($.validate.form()) {
				var data = $("#form-tJcJcbg-add").serializeArray();
				var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
				var roleIds = $.form.selectCheckeds("role");
				var postIds = $.form.selectSelects("post");
				data.push({"name": "status", "value": status});
				data.push({"name": "roleIds", "value": roleIds});
				data.push({"name": "postIds", "value": postIds});
				$.operate.saveTab(prefix + "/add", data);
			}
		}


	</script>

</body>
</html>
